//
//  CLinterViewController.m
//  I-want-go
//
//  Created by dllo on 15/10/27.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "CLinterViewController.h"
#import "BaseModel.h"
#import "CLtool.h"
#import "CLchangePic.h"
#import "CLconcreteCollectionCell.h"
#import "CLimageTableCell.h"
#import "CLlabelTableViewCell.h"
#import "CLconter.h"
#import "CLpeopleViewController.h"
#import "CLguidang.h"
//#import "CLSingleton.h"
#import "UMSocial.h"
#import "CLDataBaseHandle.h"
#import "CLsameViewController.h"
#import "CLscreen.h"
#import "CLpresentWebView.h"
@interface CLinterViewController ()<UIScrollViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate, UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, retain)NSMutableArray *arr;
@property(nonatomic, retain)UICollectionView *myCollectionView;
@property(nonatomic, retain)UIScrollView *myScrollView;
@property(nonatomic, retain)UIScrollView *rigScrollView;
@property(nonatomic, retain)UIImageView *myImage;
@property(nonatomic, retain)NSString *ss;

@property(nonatomic, retain)UIPageControl *page;

@property(nonatomic, retain)NSMutableArray *picArr;
@property(nonatomic, retain)UIScrollView *firstScrollView;
@property(nonatomic, retain)UITableView *myTabelView;
@property(nonatomic, retain)NSMutableArray *contArr;
@property(nonatomic, retain)NSString *usereId;

@property(nonatomic, retain)MBProgressHUD *hub;
@property(nonatomic, retain)CLguidang *gui;
@property(nonatomic, retain)NSString *brandId;
@property(nonatomic, retain)NSString *productUrl;
@end

@implementation CLinterViewController
- (void)dealloc {
    [_hub release];
    [_brandId release];
    [_productUrl release];
    [_gui release];
    [_usereId release];
    [_contArr release];
    [_myTabelView release];
    [_firstScrollView release];
    [_picArr release];
    [_page release];
    [_myImage release];
    [_rigScrollView release];
    [_myScrollView release];
    [_myCollectionView release];
    [_arr release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor redColor];
    
    self.firstScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 375 * SWIDTH, 731 * SHEIGHT)];
    self.firstScrollView.backgroundColor = [UIColor grayColor];
    self.firstScrollView.contentSize = CGSizeMake(2 * 375 * SWIDTH, 0);
    [self.view addSubview:self.firstScrollView];
    self.firstScrollView.pagingEnabled = YES;
    self.firstScrollView.showsHorizontalScrollIndicator = NO;
    [self.firstScrollView release];
    ///////// 侧滑之后那页
    
//    [CLsaveTool isMake];
    
    self.myTabelView = [[UITableView alloc] initWithFrame:CGRectMake(375 * SWIDTH, 0, 375 * SWIDTH, 603 * SHEIGHT)];
    [self.firstScrollView addSubview:self.myTabelView];
    [_myTabelView release];
    
    UIView *headView= [[UIView alloc] initWithFrame:CGRectMake(0, -60 * SHEIGHT, 375 * SWIDTH, 60 * SHEIGHT)];
    headView.backgroundColor = [UIColor whiteColor];
    self.myTabelView.tableHeaderView = headView;
    [headView release];
    
    UILabel *headLabel = [[UILabel alloc] initWithFrame:CGRectMake(100 * SWIDTH, 10 * SHEIGHT, 170 * SWIDTH, 40 * SHEIGHT)];
    headLabel.text = @"商品描述";
    headLabel.font = [UIFont systemFontOfSize:18];
    headLabel.textColor = [UIColor grayColor];
    headLabel.textAlignment = NSTextAlignmentCenter;
    [headView addSubview:headLabel];
    [headLabel release];
    
    
    self.myTabelView.dataSource = self;
    self.myTabelView.delegate = self;
    
    self.hub = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.hub.labelText = @"正在加载";
    
    
    ////////////// 第一页
    self.myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 375 * SWIDTH, 603 * SHEIGHT)];
    self.myScrollView.backgroundColor = [UIColor grayColor];
//    [self.view addSubview:self.myScrollView];
    [self.firstScrollView addSubview:self.myScrollView];
    self.myScrollView.showsVerticalScrollIndicator = NO;
    self.myScrollView.contentSize = CGSizeMake(0, 667 * 3 * SHEIGHT);
//    self.myScrollView.bounces = NO;
    [_myScrollView release];
    
    
    self.rigScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 375 * SWIDTH, 300 * SHEIGHT)];
    [self.myScrollView addSubview:self.rigScrollView];
    self.rigScrollView.showsHorizontalScrollIndicator = NO;
    [_rigScrollView release];
    
    
    [self createData];
    [self createDete];
    [self createMata];
}

- (void)createData {
    
    NSString *strid = [NSString stringWithFormat:@"key=045c70806c52fe6326eb2a8562629d1d&productId=%@&t=1445944613582&type=xiangqu&userId=705811&userid=705811&version=3.5.4", self.interId];
    NSString *str = @"http://api.xiangqu.com/product/content";
    NSURL *url = [NSURL URLWithString:str];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"POST"];
    NSString *bodyStr = strid;
    NSData *bodyData = [bodyStr dataUsingEncoding:NSUTF8StringEncoding];
    [request setHTTPBody:bodyData];
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
        
        
        self.gui = [[CLguidang alloc] init];
        [self.gui setValuesForKeysWithDictionary:dic[@"data"]];
//        NSLog(@"%@", self.gui.image);
    
        
        self.ss = dic[@"data"][@"image"];
    // 价钱
        NSString *price = [NSString stringWithFormat:@"💰:%@", dic[@"data"][@"price"]];
    // 包邮
        NSString *by = dic[@"data"][@"postage"];
    // 标题
        NSString *title = dic[@"data"][@"title"];
    // 喜欢
        NSString *like = [NSString stringWithFormat:@"%@", dic[@"data"][@"favNum"]];
    // 主理人
        NSString *people = dic[@"data"][@"productUser"];
    // 主理人头像
        NSString *avaPath = dic[@"data"][@"avaPath"];
    // 品牌头像
        NSString *brandStory = dic[@"data"][@"brandIcon"];
    // 品牌后
        NSString *brand = dic[@"data"][@"brand"];
        // 厂家介绍
        NSString *brandSto = dic[@"data"][@"brandStory"];
      //
        // 产品网址
        self.productUrl = dic[@"data"][@"productURL"];
        // ID
        self.usereId = dic[@"data"][@"userId"];
        
        self.brandId = dic[@"data"][@"brandId"];
        self.arr = [NSMutableArray arrayWithArray:dic[@"data"][@"imgsUrlList"]];
        [self.arr addObject:self.ss];

//        NSLog(@"%ld", self.arr.count);
        
        for (NSInteger i = 0; i < self.arr.count; i++) {
            
            self.rigScrollView.contentSize = CGSizeMake(375 * self.arr.count * SWIDTH, 0);
            self.rigScrollView.pagingEnabled = YES;
            
            self.myImage = [[UIImageView alloc] initWithFrame:CGRectMake(i * (375 * SWIDTH), 0, 375 * SWIDTH, 300 * SHEIGHT)];
            [self.rigScrollView addSubview:self.myImage];
            [_myImage release];
            
            [self.myImage sd_setImageWithURL:[NSURL URLWithString:self.arr[i]]];
           }
        
        
        
         // 加点
        
        self.page = [[UIPageControl alloc] initWithFrame:CGRectMake(100 * SWIDTH, 280 * SHEIGHT, 150 * SWIDTH, 20 * SHEIGHT)];
        self.page.backgroundColor = [UIColor clearColor];
        [self.myScrollView addSubview:self.page];
        self.page.numberOfPages = self.arr.count;
        if (self.arr.count == 1) {
            self.page.currentPageIndicatorTintColor = [UIColor clearColor];
        } else {
            self.page.currentPageIndicatorTintColor = [UIColor whiteColor];
        }

        //
        self.page.pageIndicatorTintColor = [UIColor grayColor];
        
        [self.page addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];
        
        
        self.rigScrollView.delegate = self;

///////////////////
        UIView *smallView = [[UIView alloc] initWithFrame:CGRectMake(0, 300 * SHEIGHT, 375 * SWIDTH, 100 * SHEIGHT)];
        smallView.backgroundColor = [UIColor whiteColor];
        [self.myScrollView addSubview:smallView];
        [smallView release];

        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10 * SWIDTH, 10 * SHEIGHT, 365 * SWIDTH, 50 * SHEIGHT)];
        titleLabel.font = [UIFont systemFontOfSize:18];
        titleLabel.numberOfLines = 0;
        [smallView addSubview:titleLabel];
        [titleLabel release];
        titleLabel.text = title;
        
        UIButton *buyButton = [UIButton buttonWithType:UIButtonTypeSystem];
        buyButton.frame = CGRectMake(285 * SWIDTH, 45 *SHEIGHT, 80 *SWIDTH, 20 *SHEIGHT);
        [smallView addSubview:buyButton];
        [buyButton setTitle:@"点我去购" forState:UIControlStateNormal];
        [buyButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [buyButton addTarget:self action:@selector(cliBuy:) forControlEvents:UIControlEventTouchUpInside];
        
        UILabel *priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(10 * SWIDTH, 70 * SHEIGHT, 120 * SWIDTH, 20 * SHEIGHT)];
        [smallView addSubview:priceLabel];
        [priceLabel release];
        priceLabel.textColor = [UIColor grayColor];
        priceLabel.text = price;
        
        UILabel *youLabel = [[UILabel alloc] initWithFrame:CGRectMake(110 * SWIDTH, 70 * SHEIGHT, 90 * SWIDTH, 20 * SHEIGHT)];
        youLabel.font = [UIFont systemFontOfSize:14];
        [smallView addSubview:youLabel];
        [youLabel release];
        youLabel.text = by;
        
        UIButton *thinkButton = [UIButton buttonWithType:UIButtonTypeSystem];
        thinkButton.frame = CGRectMake(320 * SWIDTH, 70 * SHEIGHT, 55 * SWIDTH, 20 * SHEIGHT);
        [smallView addSubview:thinkButton];
        [thinkButton setTitle:@"分享" forState:UIControlStateNormal];
        [thinkButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [thinkButton addTarget:self action:@selector(fenxiang:) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *likeButton = [UIButton buttonWithType:UIButtonTypeSystem];
        likeButton.frame = CGRectMake(210 * SWIDTH, 70 * SHEIGHT, 50 * SWIDTH, 20 * SHEIGHT);
        [smallView addSubview:likeButton];
        [likeButton setTitle:@"❤️:" forState:UIControlStateNormal];
        [likeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        UILabel *likeLabel = [[UILabel alloc] initWithFrame:CGRectMake(260 * SWIDTH, 70 * SHEIGHT, 50 * SWIDTH, 20 * SHEIGHT)];
        [smallView addSubview:likeLabel];
        [likeLabel release];
        likeLabel.text = like;
/////////////// 下面框
        UIView *nextView = [[UIView alloc] initWithFrame:CGRectMake(0, 415 * SHEIGHT, 375 * SWIDTH, 50 * SHEIGHT)];
        nextView.backgroundColor = [UIColor whiteColor];
        [self.myScrollView addSubview:nextView];
        [nextView release];
        
        UIImageView *rrrImage = [[UIImageView alloc] initWithFrame:CGRectMake(5 * SWIDTH, 10 * SHEIGHT, 30 * SWIDTH, 30 * SHEIGHT)];
        [nextView addSubview:rrrImage];
        [rrrImage release];
        [rrrImage sd_setImageWithURL:[NSURL URLWithString:avaPath]];
        
        UILabel *leadLabel = [[UILabel alloc] initWithFrame:CGRectMake(45 * SWIDTH, 15 * SHEIGHT, 70 * SWIDTH, 20 * SHEIGHT)];
        leadLabel.textColor = [UIColor grayColor];
        leadLabel.text = @"主理人:";
        [nextView addSubview:leadLabel];
        [leadLabel release];
        
        UILabel *workLabel = [[UILabel alloc] initWithFrame:CGRectMake(118 * SWIDTH, 15 * SHEIGHT, 200 * SWIDTH, 20 * SHEIGHT)];
        [nextView addSubview:workLabel];
        [workLabel release];
        workLabel.text = people;
        // 增加点击方法
//        UITapGestureRecognizer *tag = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tagAction:)];
//        [nextView addGestureRecognizer:tag];
      //////////////////////
        
        UIView *brandView = [[UIView alloc] init];
        brandView.backgroundColor = [UIColor whiteColor];
        [self.myScrollView addSubview:brandView];
        [brandView release];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(taaaAction:)];
        [brandView addGestureRecognizer:tap];
        
        UIImageView *sssImage = [[UIImageView alloc] initWithFrame:CGRectMake(5 * SWIDTH, 10 * SHEIGHT, 30 * SWIDTH, 30 * SHEIGHT)];
        [brandView addSubview:sssImage];
        [sssImage release];
        [sssImage sd_setImageWithURL:[NSURL URLWithString:brandStory]];
        
        UILabel *brandLabel = [[UILabel alloc] initWithFrame:CGRectMake(45 * SWIDTH, 15 * SHEIGHT, 70 * SHEIGHT, 20 * SWIDTH)];
        brandLabel.textColor = [UIColor grayColor];
        brandLabel.text = @"品牌:";
        [brandView addSubview:brandLabel];
        [brandLabel release];
        
        UILabel *woLabel = [[UILabel alloc] initWithFrame:CGRectMake(118 * SWIDTH, 15 * SHEIGHT, 200 * SWIDTH, 20 * SHEIGHT)];
        [brandView addSubview:woLabel];
        [woLabel release];
        woLabel.text = brand;
        
        
        UILabel *proLabel = [[UILabel alloc] initWithFrame:CGRectMake(10 * SWIDTH, 50 * SHEIGHT, 365 * SWIDTH, 40 * SHEIGHT)];
        proLabel.textColor = [UIColor grayColor];
        [brandView addSubview:proLabel];
               proLabel.numberOfLines = 0;
        proLabel.text = brandSto;
        [proLabel sizeToFit];
        brandView.frame = CGRectMake(0, 466 * SHEIGHT, 375 * SWIDTH, (proLabel.frame.size.height + 60) * SHEIGHT);
    /////////////////
         UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc] init];
        flowlayout.itemSize = CGSizeMake(50 * SWIDTH, 50 * SHEIGHT);
     self.myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, (527 + proLabel.frame.size.height) * SHEIGHT, 375 * SWIDTH, 90 * SHEIGHT) collectionViewLayout:flowlayout];
        self.myCollectionView.backgroundColor = [UIColor whiteColor];
        [self.myScrollView addSubview:self.myCollectionView];
        [_myCollectionView release];
        [self.myCollectionView registerClass:[CLconcreteCollectionCell class] forCellWithReuseIdentifier:@"raue"];
        flowlayout.sectionInset = UIEdgeInsetsMake(30 * SHEIGHT, 10 * SWIDTH, 2 * SHEIGHT, 2 * SHEIGHT);
        flowlayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
       
        UILabel *liLabel = [[UILabel alloc] initWithFrame:CGRectMake(5 * SWIDTH, 2 * SHEIGHT, 100 * SWIDTH, 30 * SHEIGHT)];
        liLabel.text = [NSString stringWithFormat:@"喜欢:%@", like];
        liLabel.textColor = [UIColor grayColor];
        [self.myCollectionView addSubview:liLabel];
        [liLabel release];
        
        self.myCollectionView.dataSource = self;
        self.myCollectionView.delegate = self;
    ////////////////////////
        
        UILabel *seeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, (618 + proLabel.frame.size.height) * SHEIGHT, 375 * SWIDTH, 60 * SHEIGHT)];
        seeLabel.backgroundColor = [UIColor whiteColor];
        [self.myScrollView addSubview:seeLabel];
        seeLabel.text = @"左划为商品详情";
        seeLabel.textAlignment = NSTextAlignmentCenter;
        seeLabel.textColor = [UIColor grayColor];
        seeLabel.font = [UIFont systemFontOfSize:25];
        [seeLabel release];
        
        [self.myScrollView sizeToFit];
        self.myScrollView.contentSize = CGSizeMake(0, (680 + proLabel.frame.size.height) * SHEIGHT);
        
        
        [CLDataBaseHandle shareDataBasaHandle];
            [[CLDataBaseHandle shareDataBasaHandle] createTable];
//
        NSLog(@"1");
        NSLog(@"%@", self.gui);
        
     //////判断是否有无
        SelectCLguidang result = [[CLDataBaseHandle shareDataBasaHandle] isHaveInTable:self.gui];
        if (result == Intable) {
            self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"已收藏" style:UIBarButtonItemStyleDone target:self action:@selector(click:)];
        } else if (result == NotInTable) {
             self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"收藏" style:UIBarButtonItemStyleDone target:self action:@selector(click:)];
        } else {
            NSLog(@"出错");
        }
//        if ([CLsaveTool ishaveNameInPlist:self.gui]) {
//            self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"收藏" style:UIBarButtonItemStyleDone target:self action:@selector(click:)];
//            
//        }
//        else {
//            self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"已收藏" style:UIBarButtonItemStyleDone target:self action:@selector(click:)] ;
//        }
        self.hub.hidden = YES;
    }];
    
}

- (void)createDete {
    NSString *strid = [NSString stringWithFormat:@"key=045c70806c52fe6326eb2a8562629d1d&productId=%@&t=1445944613582&type=xiangqu&userId=705811&userid=705811&version=3.5.4", self.interId];
    NSString *str = @"http://api.xiangqu.com/product/faver";
    NSURL *url = [NSURL URLWithString:str];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"POST"];
    NSString *bodyStr = strid;
    NSData *bodyData = [bodyStr dataUsingEncoding:NSUTF8StringEncoding];
    [request setHTTPBody:bodyData];
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
        
        self.picArr = [NSMutableArray array];
        self.picArr = [CLchangePic baseModelByArr:dic[@"data"]];
        [self.myCollectionView reloadData];
        
    }];
}

// 后面详情数据
- (void)createMata {
    NSString *strid = [NSString stringWithFormat:@"key=045c70806c52fe6326eb2a8562629d1d&productId=%@&t=1445944613582&type=xiangqu&userId=705811&userid=705811&version=3.5.4", self.interId];
    NSString *str = @"http://api.xiangqu.com/product/chips";
    NSURL *url = [NSURL URLWithString:str];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"POST"];
    NSString *bodyStr = strid;
    NSData *bodyData = [bodyStr dataUsingEncoding:NSUTF8StringEncoding];
    [request setHTTPBody:bodyData];
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
        
        self.contArr = [NSMutableArray array];
        self.contArr = [CLconter baseModelByArr:dic[@"data"]];
        
        [self.myTabelView reloadData];
        
    }];
    
//    NSLog(@"2");
    
}

- (void)tamAction:(UIGestureRecognizer *)tap11 {
    NSLog(@"1");
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (self.picArr.count > 6) {
        return 6;
    } else {
        return self.picArr.count;
    }
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    CLconcreteCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"raue" forIndexPath:indexPath];
    CLchangePic *change = self.picArr[indexPath.row];
    if (self.picArr.count > 6) {
        if (indexPath.row == 5) {
            cell.likeImage.image = [UIImage imageNamed:@"right.png"];
        } else {
                  [cell.likeImage sd_setImageWithURL:[NSURL URLWithString:change.avaPath]];
        }
      
    } else {
         [cell.likeImage sd_setImageWithURL:[NSURL URLWithString:change.avaPath]];
    }
        return cell;
    
}








// 点击手势
//- (void)tagAction:(UITapGestureRecognizer *)tag {
////    NSLog(@"点击");
//    
//    CLpeopleViewController *pepVC = [[CLpeopleViewController alloc] init];
//    [self.navigationController pushViewController:pepVC animated:YES];
//    
//    pepVC.strId = self.usereId;
// }

- (void)taaaAction:(UITapGestureRecognizer *)tap {
    
    CLsameViewController *artVC = [[CLsameViewController alloc] init];
    [self.navigationController pushViewController:artVC animated:YES];
    // 传个id
    
    artVC.sameId = self.brandId;
    
}


- (void)pageAction:(UIPageControl *)page {
    [self.rigScrollView setContentOffset:CGPointMake((self.page.currentPage + 1)* 150, 0) animated:YES];
    
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    if (scrollView == self.rigScrollView) {
        if (scrollView.contentOffset.x == (self.arr.count + 1) * (self.view.frame.size.width)) {
            scrollView.contentOffset = CGPointMake((self.view.frame.size.width), 0);
        }
        self.page.currentPage = scrollView.contentOffset.x / (self.view.frame.size.width);
    }
}

////////tableview
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.contArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    self.myTabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
    CLconter *cont = self.contArr[indexPath.row];
    if ([cont.isImg integerValue] == 1) {
        self.myTabelView.rowHeight = 300 * SHEIGHT;
        static NSString *reuse = @"reuu";
        CLimageTableCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[CLimageTableCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuse];
        }
        [cell.contImage sd_setImageWithURL:[NSURL URLWithString:cont.content]];
        
             return cell;
    }
    else {
        
        static NSString *reuse = @"rmmm";
        CLlabelTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[CLlabelTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuse];
        }
//        self.myTabelView.rowHeight = cell.contlabel.frame.size.height + 50;
        cell.contlabel.text = cont.content;
//    NSLog(@"%@", cont.content);
        return cell;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    CLconter *cont = self.contArr[indexPath.row];
    if (![cont.isImg integerValue] == 1) {
   
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:16], NSFontAttributeName, nil];
    CGRect rect = [cont.content boundingRectWithSize:CGSizeMake(365 * SWIDTH, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return (rect.size.height + 5) * SHEIGHT;
    } else {
        return 300 * SHEIGHT;
    }
}

// 分享
- (void)fenxiang:(UIButton *)button {
    
    [UMSocialSnsService presentSnsIconSheetView:self
            appKey:@"56389acb67e58ef61f00030c"
                                      shareText:[NSString stringWithFormat:@"分享:%@", self.productUrl]
    shareImage:[UIImage imageNamed:@"icon.png"]
    shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina, UMShareToRenren, UMShareToEmail,nil]
                            delegate:nil];
    
    NSLog(@"1");
    
}

- (void)click:(UIBarButtonItem *)button {
    
    if ([button.title isEqualToString:@"收藏"]) {
        
//        if ([CLSingleton shareSingleton].islog == YES) {
            [[CLDataBaseHandle shareDataBasaHandle] saveMovieInDB:self.gui];
            button.title = @"已收藏";
//        } else {
//            UIAlertController *aleryController = [UIAlertController alertControllerWithTitle:@"没有登录" message:@"请登录" preferredStyle:UIAlertControllerStyleAlert];
//            [self presentViewController:aleryController animated:YES completion:nil];
//            UIAlertAction *leftAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];
//            [aleryController addAction:leftAction];
//        }
    } else {
        [[CLDataBaseHandle shareDataBasaHandle] deleteGuiInDB:self.gui];
        button.title = @"收藏";
    }
    
}

- (void)cliBuy:(UIButton *)button {
//    NSLog(@"1");
    
    CLpresentWebView *webVC = [[CLpresentWebView alloc] init];
    [self.navigationController pushViewController:webVC animated:YES];
    
    webVC.webStr = self.productUrl;
    
}



- (void)viewWillAppear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = NO;
}





// button
//- (void)click:(UIBarButtonItem *)button {
//    
//    if ([button.title isEqualToString:@"已收藏"]) {
//        [CLsaveTool cancleNameInPlist:self.gui];
//        button.title = @"收藏";
//    } else {
//        [CLsaveTool saveNameToPlist:self.gui];
//        button.title =@"已收藏";
//    }
//    
//}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
